package org.dromara.tearoom.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.tearoom.service.impl.TerLockSerialnumServiceImpl;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.tearoom.domain.vo.TerDoorEventVo;
import org.dromara.tearoom.domain.bo.TerDoorEventBo;
import org.dromara.tearoom.service.ITerDoorEventService;

/**
 * 茶室开门记录
 * 前端访问路由地址为:/tearoom/doorEvent
 *
 * @author xiechh
 * @date 2025-04-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/doorEvent")
public class TerDoorEventController extends BaseController {

    private final ITerDoorEventService terDoorEventService;

    /**
     * 查询茶室开门记录列表
     */
    @SaCheckPermission("tearoom:doorEvent:list")
    @GetMapping("/list")
    public TableDataInfo<TerDoorEventVo> list(TerDoorEventBo bo, PageQuery pageQuery) {
        return terDoorEventService.queryPageList(bo,pageQuery);
    }

    /**
     * 导出茶室开门记录列表
     */
    @SaCheckPermission("tearoom:doorEvent:export")
    @Log(title = "茶室开门记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerDoorEventBo bo, HttpServletResponse response) {
        List<TerDoorEventVo> list = terDoorEventService.queryList(bo);
        ExcelUtil.exportExcel(list, "茶室开门记录", TerDoorEventVo.class, response);
    }

    /**
     * 获取茶室开门记录详细信息
     *
     * @param eventid 主键
     */
    @SaCheckPermission("tearoom:doorEvent:query")
    @GetMapping("/{eventid}")
    public R<TerDoorEventVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("eventid") Long eventid) {
        return R.ok(terDoorEventService.queryById(eventid));
    }

    /**
     * 新增茶室开门记录
     */
    @SaCheckPermission("tearoom:doorEvent:add")
    @Log(title = "茶室开门记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerDoorEventBo bo) {
        return toAjax(terDoorEventService.insertByBo(bo));
    }

    /**
     * 修改茶室开门记录
     */
    @SaCheckPermission("tearoom:doorEvent:edit")
    @Log(title = "茶室开门记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerDoorEventBo bo) {
        return toAjax(terDoorEventService.updateByBo(bo));
    }

    /**
     * 删除茶室开门记录
     *
     * @param eventids 主键串
     */
    @SaCheckPermission("tearoom:doorEvent:remove")
    @Log(title = "茶室开门记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{eventids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("eventids") Long[] eventids) {
        return toAjax(terDoorEventService.deleteWithValidByIds(List.of(eventids), true));
    }
}
